package sort;

import sort.primarySort.Insertion;
import sort.primarySort.Selection;
import sort.primarySort.Shell;

public class SortCompare {
    public static void test(String sort_algo1, String sort_algo2, int m, int n) {
        double total1 = 0.0;
        double total2 = 0.0;
        for (int i = 0; i < m; i++) {
            Comparable[] array = getArray(n);
            total1 += time(array, sort_algo1);
            total2 += time(array, sort_algo2);
        }

        System.out.printf("%d random Doubles", n);
        System.out.printf("    %s is %.2f times faseter than %s\n", sort_algo1, total2 / total1, sort_algo2);

    }

    public static double time(Comparable[] a, String sort_algo) {
        double start = System.currentTimeMillis();
        if (sort_algo.equals("Selection")) Selection.sort(a);
        if (sort_algo.equals("Insertion")) Insertion.sort(a);
        if (sort_algo.equals("Shell")) Shell.sort(a);


        double end = System.currentTimeMillis();
//        double time = Double.parseDouble(String.format("%.2f", end-start));
        return end - start;
    }

    public static Comparable[] getArray(int n) {
        Double[] array = new Double[n];
        for (int i = 0; i < n; i++) {
            array[i] = Double.parseDouble(String.format("%.3f", Math.random()));
        }
        return array;
    }
}
